﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Diagnostics;
using GamePlugin.Logics.Core;
using GamePlugin.Logics;
using GamePlugin.Logics.Game.Actions;

namespace GamePlugin
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            if (Workspace.Instance.SearchInfoItemList == null) ;

            InitializeComponent();

            CompositionTarget.Rendering += new EventHandler(CompositionTarget_Rendering);
        }

        void CompositionTarget_Rendering(object sender, EventArgs e)
        {
            Time.Tick();
            GameTime gameTime = new GameTime(Time.DeltaTime, Time.TotalTime);
            Workspace.Instance.DiabloPluginGame.Update(gameTime);
        }

        private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
        {
            if (MessageBox.Show("是否存儲所有內容？", "存檔", MessageBoxButton.OKCancel) == MessageBoxResult.OK)
            {
                Workspace.Instance.SaveAll();
            }
        }

        private void LaunchCommand_Executed(object sender, ExecutedRoutedEventArgs e)
        {
            Workspace.Instance.DiabloPluginGame.Root.ChangeToState(typeof(DActionRun).Name);
        }

        private void StopCommand_Executed(object sender, ExecutedRoutedEventArgs e)
        {
            Workspace.Instance.DiabloPluginGame.Root.ChangeToState(typeof(DActionIdle).Name);
            Workspace.Instance.DiabloPluginGame.Root.IsNeedReset = true;
        }

        private void Save_Click(object sender, RoutedEventArgs e)
        {
            Workspace.Instance.SaveAll();
        }

        private void Load_Click(object sender, RoutedEventArgs e)
        {
            Workspace.Instance.LoadAll();
        }
    }
}
